<template>
  <div id="done_main">
    <el-row :gutter="20">
      <el-col :span="24" :offset="0">
        <el-table :data.sync="tableData" border stripe>
          <el-table-column prop="id" label="ID" width="150">
          </el-table-column>
          <el-table-column prop="name" label="姓名" width="150">
          </el-table-column>
          <el-table-column prop="tag" label="标签" width="150">
          </el-table-column>
          <el-table-column prop="id" label="操作" width="150">
            <template slot-scope="scope">
              <el-button type="primary" size="small" @click="doSomething(scope.row.id)">操作</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="24" :offset="0">
        <paging ref="pager" :doQuery="doQuery" />
        <button @click="refreshTable">请求</button>
      </el-col>
    </el-row>


  </div>
</template>

<script>
import service from '@/utils/request'
import Paging from '../../components/paging.vue'

export default {
  components: {
    'paging': Paging
  },
  data() {
    return {
      tableData: []
    }
  },


  methods: {
    refreshTable() {
      this.$refs.pager.reload()
    },
    doQuery(pageNum, pageSize) {
      service({
        ws: false,
        url: '/test/page',
        method: 'get',
        params: { pageSize: pageSize, pageNum: pageNum }
      })
        .then(res => {
          if (res.status === 'success') {
            //取走数据
            this.tableData = res.data
            this.$refs.pager.setMaxRows(res.maxRows)
          } else {
            alert("错误" + res.msg)
          }
        })
        .catch(err => {
          console.error(err);
        })
    },
    doSomething(id) {
      alert("操作了ID" + id)
    }
  }
}
</script>

<style scoped>
#done_main {
  width: 100%
}
</style>